package _3TCPChat;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class ChatClientFrame extends JFrame {

	
	JTextArea area;
	
	
	ChatClient client;
	
	public void showMsg(String msg)
	{
		area.append(msg+"\n");
	}

	public ChatClientFrame() {
 


		
		// 多行文本框
		area = new JTextArea();
		// 滑动条区域
		JScrollPane scroll = new JScrollPane(area);
		area.setText("客户端准备");
		this.add(scroll, BorderLayout.CENTER);

		// 输入框和发送按钮
		JPanel p = new JPanel();
		JTextField inputText = new JTextField(20);
		p.add(inputText);
		JButton btn = new JButton("发送");
		p.add(btn);
		this.add(p, BorderLayout.SOUTH);
		
		btn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) 
			{
				// 内容
				String msg = inputText.getText();
				client.send(msg);
			}
		});
		
		client = new ChatClient();
		client.f = this;
		client.connect();

	}

	public static void main(String[] args) {

		ChatClientFrame f = new ChatClientFrame();

		f.setVisible(true);

		f.setBounds(100, 100, 400, 300);
		
		// 当关闭窗口 ，退出
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}
}
